package com.bw.http.http.okhttp

import com.blankj.utilcode.util.SPUtils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

class RetrofitUtils {
    companion object{
        fun getRetrofit():Retrofit{
            val client = OkHttpClient.Builder()
                .writeTimeout(30,TimeUnit.SECONDS)
                .readTimeout(30,TimeUnit.SECONDS)
                .connectTimeout(30,TimeUnit.SECONDS)
                .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                .addInterceptor {
                    val token = SPUtils.getInstance().getString("token","eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxOTIzMzE2MzM4NCJ9.M8_GNczI9HXSmPw6ln1cPqs62TqXcECDIn3lufVO5mg")
                    val request = it.request().newBuilder()
                        .addHeader("token",token)
                        .addHeader("accessId","00a5a3682f7840a8803ab10eb0434cbf")
                        .build()
                    it.proceed(request)
                }
                .build()
            val retrofit = Retrofit.Builder()
                .client(client)
                .baseUrl("http://10.161.9.80:2209")
                .addConverterFactory(GsonConverterFactory.create())
                .build()
            return retrofit
        }
    }
}